home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
autopaint
/
modcolor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
121 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include "lum.h"
#include "canvas.h"
#define NRTABS 20
static int isat;
static unsigned char *rtabs[NRTABS];
static pixel backcol;
setbackcolor(col)
pixel *col;
{
backcol = *col;
}
setsaturate(sat)
float sat;
{
if(sat<0.0)
sat = 0.0;
isat = 255*sat;
}
setnoisemag(mag)
float mag;
{
int i, v, maxdel, idel;
unsigned char *cptr;
if(mag<0.0)
mag = 0.0;
if(mag>1.0)
mag = 1.0;
if(!rtabs[0]) {
for(i=0; i<NRTABS; i++)
rtabs[i] = (unsigned char *)malloc(256*sizeof(char));
}
maxdel = 127*mag;
for(i=0; i<NRTABS; i++) {
cptr = rtabs[i];
for(v=0; v<256; v++) {
idel = maxdel;
if(v<idel)
idel = v;
if((255-v)<idel)
idel = 255-v;
idel++;
if(random()%0x8)
*cptr++ = v+(random()%idel);
else
*cptr++ = v-(random()%idel);
}
}
}
modifycolor(col)
pixel *col;
{
long int bw, r, g, b;
int curtab;
if(colorsame(col,&backcol))
return;
r = col->r;
g = col->g;
b = col->b;
bw = ILUM(r,g,b);
bw = bw*(256-isat);
r = (bw+isat*r)>>8;
g = (bw+isat*g)>>8;
b = (bw+isat*b)>>8;
if(r<0) r = 0; else if(r>255) r = 255;
if(g<0) g = 0; else if(g>255) g = 255;
if(b<0) b = 0; else if(b>255) b = 255;
curtab = random()%(NRTABS-3);
r = rtabs[curtab++][r];
g = rtabs[curtab++][g];
b = rtabs[curtab++][b];
col->r = r;
col->g = g;
col->b = b;
}
colorsame(c1,c2)
pixel *c1, *c2;
{
if(c1->r != c2->r)
return 0;
if(c1->g != c2->g)
return 0;
if(c1->b != c2->b)
return 0;
return 1;
}
int colordelta(c1,c2)
pixel *c1, *c2;
{
int dr, dg, db;
dr = RINTLUM*(c1->r-c2->r);
dg = GINTLUM*(c1->g-c2->g);
db = BINTLUM*(c1->b-c2->b);
return fsqrt((float)dr*dr+dg*dg+db*db)+0.5;
}